package com.lemo.dao;


import com.lemo.bean.User;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.io.Serializable;

@Repository
public class UserDaoImpl implements UserDao {

    @PersistenceContext
    private EntityManager entityManager;


    @Override
    public User get(Serializable id) {
        return entityManager.find(User.class, id);
    }

    @Override
    public User update(User record) throws Exception {
        return entityManager.merge(record);
    }

    @Override
    public User add(User record) throws Exception {
        return entityManager.merge(record);
    }

    @Override
    public void del(Serializable id) {
        entityManager.createNativeQuery("delete from user where id=" + id).executeUpdate();
    }

}
